GBML manual / Motion

hsp

Horizontal speed, in pixels per frame - positive is right.

Syntax

hsp: real

Description

Horizontal speed, in pixels moved per frame - positive is right, negative is left. Set it directly for movement that only ever runs along the room's axes (a platformer's walk cycle, a shooter's strafe) without needing an angle at all.

hsp/vsp and speed/direction are two views onto the same underlying motion, kept in sync every frame - and each stays fully authoritative for as long as you keep using it, every frame, forever. The engine remembers which pair you actually wrote to last, so whichever one a script sets THIS frame wins, no matter what the other pair already holds: set hsp/vsp directly every frame (a car, a ball) and they are never overridden by a stale speed/direction; set speed/direction every frame instead and the reverse holds. Read the other pair back at any time and you will see a sane, up-to-date answer either way. The one thing to know about gravity: it accumulates cleanly whenever an instance leaves speed untouched (the usual "falls under gravity, moves sideways by setting hsp directly" shape) or keeps reasserting the exact same speed/direction every frame - only a script that retargets speed/direction to a genuinely new value every frame (chasing a moving target, say) overrides gravity's own contribution each time, because that script is telling the engine "this is my velocity now."

Example

hsp = btn_dx() * 1.5;

A direct, angle-free strafe: btn_dx() reads -1/0/1 off the d-pad, scaled to 1.5 pixels a frame either way.

On the GBA

Setting `speed`/`direction` and hsp/vsp "and back" works both ways, EVERY frame, forever. The engine remembers what it last derived for both pairs and compares each one against that memory, not against 0 - so whichever pair a script genuinely wrote THIS frame wins, independent of whatever the other pair already holds, and a script that sets hsp/vsp fresh every single frame keeps winning every frame, not just the first.

See also: vspspeeddirectiongravityWhere the machine shows through